/***************************************************************************
 *   Copyright (C) 2007 by Alexandre Masselot,,,   *
 *   alex@alex-laptop   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "runlcmsmsreader.h"

namespace bol {

  RunLcmsmsReader::RunLcmsmsReader()
  {
    m_inputStream=NULL;
    m_defaultcharge=0;
  }


  RunLcmsmsReader::~RunLcmsmsReader()
  {
    if(m_inputStream)
      delete m_inputStream;
  }

  void RunLcmsmsReader::read(RunLcmsms& run, istream* newStream){
    if(inputStream()!=NULL){
      delete inputStream();
    }
    setInputStream(newStream);
    assert(inputStream()->good());

    while(nextSpectrum(run)){
      // TODO if we use a compressed stream, chances are high that the data set will be huge and will take some time to process we should consider making some progress status indicator.
    }
  }
  
  void RunLcmsmsReader::read(RunLcmsms& run, const string& filename){
    if(inputStream()!=NULL){
      delete inputStream();
    }
    setInputStream(new ifstream(filename.c_str()));
    assert(inputStream()->good());

    init(run, inputStream());
    while(nextSpectrum(run)){}
  }
  
}
